Skip to content

perf(guest): read the private input zero-copy via ef_io::read_input - #886

Merged
MauroToscano merged 7 commits into
mainfrom
perf/guest-zerocopy
Aug 4, 2026
Merged

perf(guest): read the private input zero-copy via ef_io::read_input#886
MauroToscano merged 7 commits into
mainfrom
perf/guest-zerocopy

Conversation

@diegokingston

Copy link
Copy Markdown
Collaborator

get_private_input() to_vec()'s the whole memory-mapped input before rkyv deserializes it; read_input hands rkyv a slice straight into the input region instead. Same bytes, same private-input commitment.

Measured vs origin/main (same fixtures, deterministic):
transfers_20 8,732,213 -> 8,692,490 (-39,723)
erc20_20 10,328,222 -> 10,278,822 (-49,400)
mixed_20 9,817,444 -> 9,768,492 (-48,952)

Verified: test_prove_ethrex_empty_block (prove+verify) passes.

get_private_input() to_vec()'s the whole memory-mapped input before rkyv
deserializes it; read_input hands rkyv a slice straight into the input
region instead. Same bytes, same private-input commitment.

Measured vs origin/main (same fixtures, deterministic):
  transfers_20  8,732,213 -> 8,692,490  (-39,723)
  erc20_20     10,328,222 -> 10,278,822 (-49,400)
  mixed_20      9,817,444 -> 9,768,492  (-48,952)

Verified: test_prove_ethrex_empty_block (prove+verify) passes.
@diegokingston

Copy link
Copy Markdown
Collaborator Author

/bench

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown

Benchmark — real block (ethrex_mainnet_25368371.bin) (median of 3)

continuations · epoch 2^22 · 12 epochs

Metric main PR Δ
Peak heap 48519 MB 45915 MB -2604 MB (-5.4%) 🟢
Prove time 166.381s 158.246s -8.135s (-4.9%) ⚪

-4.9% — beyond what 3 runs resolve. Use /bench-abba for a paired test of the same block (default 12 pairs, ~72 min, resolves ~1%).

Prove-time spread 1.2% (158.246s / 159.049s / 157.171s)

Commit: a6ca32e · Baseline: cached · Runner: self-hosted bench

@diegokingston

Copy link
Copy Markdown
Collaborator Author

/bench

@diegokingston

Copy link
Copy Markdown
Collaborator Author

/bench

@diegokingston
diegokingston marked this pull request as ready for review August 3, 2026 14:51
@MauroToscano

Copy link
Copy Markdown
Contributor

/bench

…lice (#898)

The zero-copy read is the right call, but it hand-rolls what
`syscalls::get_private_input_slice` already does: borrow the mapped
private-input region in place and hand back `&'static [u8]`, no copy and no
allocation. `get_private_input` is that same call plus a `to_vec()`, so
dropping to the slice is the whole win without the pointer plumbing.

Three things that buys:

- No raw pointers in guest code. `syscalls.rs` deliberately keeps the region
  layout and its one `unsafe` block in a single place — that is why
  `get_private_input_slice` exists. Re-reading the length prefix in the guest
  duplicates layout knowledge that has to stay in step with the executor.
- Restores the length-prefix clamp. `get_private_input_slice` bounds the
  prefix by `MAX_PRIVATE_INPUT_SIZE`; `ef_io::read_input` returns it raw. The
  executor rejects oversized inputs, so honest runs are identical — but a
  forged prefix built a slice reaching past the region instead of a bounded
  one.
- Drops a dependency on unspecified behavior. `ef_io::read_input` documents
  `buf_ptr` as unspecified when `buf_size == 0`, and the previous code fed it
  to `from_raw_parts` regardless. Harmless in practice (the implementation
  always writes it, and ethrex input is never empty), but not a contract to
  lean on.

`bench_vs/lambda/recursion` already reads its blob this way.
@MauroToscano
MauroToscano enabled auto-merge August 4, 2026 19:29
@MauroToscano
MauroToscano disabled auto-merge August 4, 2026 19:36
@MauroToscano

Copy link
Copy Markdown
Contributor

/bench

@MauroToscano
MauroToscano enabled auto-merge August 4, 2026 19:42
@MauroToscano
MauroToscano added this pull request to the merge queue Aug 4, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 4, 2026
@MauroToscano
MauroToscano added this pull request to the merge queue Aug 4, 2026
Merged via the queue into main with commit 8b88a8d Aug 4, 2026
15 checks passed
@MauroToscano
MauroToscano deleted the perf/guest-zerocopy branch August 4, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants